package com.anivia.common.log.config;

import com.anivia.common.log.DefaultRequestLogHandler;
import com.anivia.common.log.RequestLogHandler;
import com.anivia.common.log.filter.RequestLogFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 请求日志自动配置类
 *
 * @author wangj
 */
@Configuration
public class RequestLogFilterAutoConfiguration {
    @Bean
    public FilterRegistrationBean<RequestLogFilter> requestLogFilter(
            RequestLogHandler requestLogHandler) {
        FilterRegistrationBean<RequestLogFilter> bean = new FilterRegistrationBean<>();
        bean.setFilter(new RequestLogFilter(requestLogHandler));
        return bean;
    }

    @Bean
    public RequestLogHandler requestLogHandler() {
        return new DefaultRequestLogHandler();
    }
}
